package btanalyzer.db.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

@Entity
@Table(name="METADATA")
public class Metadata {

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq")
    @SequenceGenerator(name = "seq", sequenceName = "METADATA_SEQ")
    @Column(name="METADATA_ID")
	private Long id;
	public void setId(Long id) {
		this.id = id;
	}
	public Long getId() {
		return id;
	}
	
	@NotNull
	@Column(name="NAME")
	private String name;
	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}
	
	@NotNull
	@Column(name="SIZE_IN_BYTES")
	private Long sizeInBytes;
	public void setSizeInBytes(Long sizeInBytes) {
		this.sizeInBytes = sizeInBytes;
	}
	public Long getSizeInBytes() {
		return sizeInBytes;
	}

    @NotNull
    @Column(name="ANNOUNCE_URL")
    private String announceUrl;
    public void setAnnounceUrl(String announceUrl) {
		this.announceUrl = announceUrl;
	}
    public String getAnnounceUrl() {
		return announceUrl;
	}

    @NotNull
    @Column(name="PIECE_QUANTITY")
    private Integer pieceQuantity;
    public void setPieceQuantity(Integer pieceQuantity) {
		this.pieceQuantity = pieceQuantity;
	}
    public Integer getPieceQuantity() {
		return pieceQuantity;
	}
    
    @NotNull
    @Column(name="PIECE_SIZE_IN_BYTES")
    private Long pieceSizeInBytes;
    public void setPieceSizeInBytes(Long pieceSizeInBytes) {
		this.pieceSizeInBytes = pieceSizeInBytes;
	}
    public Long getPieceSizeInBytes() {
		return pieceSizeInBytes;
	}

    @Column(name="CREATION_DATE")
    private Date creationDate;
    public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}
    public Date getCreationDate() {
		return creationDate;
	}

    @Column(name="DESCRIPTION")
    private String description;
    public void setDescription(String description) {
		this.description = description;
	}
    public String getDescription() {
		return description;
	}
    
    @NotNull
    @Column(name="DOWNLOADED_DATE")
    private Date downloadedDate;
    public void setDownloadedDate(Date downloadedDate) {
		this.downloadedDate = downloadedDate;
	}
    public Date getDownloadedDate() {
		return downloadedDate;
	}
    
    @NotNull
    @OneToOne(mappedBy="metadata")
    private Torrent torrnet;
    public void setTorrnet(Torrent torrnet) {
		this.torrnet = torrnet;
	}
    public Torrent getTorrnet() {
		return torrnet;
	}
    
    @OneToMany(mappedBy="metadata", cascade=CascadeType.ALL)
    private Set<ResourceFile> resourceFiles = new HashSet<ResourceFile>();
    public void setResourceFiles(Set<ResourceFile> resourceFiles) {
		this.resourceFiles = resourceFiles;
	}
    public Set<ResourceFile> getResourceFiles() {
		return resourceFiles;
	}
    
    @OneToMany(mappedBy="metadata", cascade=CascadeType.ALL)
    Set<MetadataAnnounceUrl> metadataAnnounceUrls = new HashSet<MetadataAnnounceUrl>();
    public void setMetadataAnnounceUrls(
			Set<MetadataAnnounceUrl> metadataAnnounceUrls) {
		this.metadataAnnounceUrls = metadataAnnounceUrls;
	}
    public Set<MetadataAnnounceUrl> getMetadataAnnounceUrls() {
		return metadataAnnounceUrls;
	}
	@Override
	public String toString() {
		return "[id=" + id + ", name=" + name + ", sizeInBytes="
				+ sizeInBytes + ", announceUrl=" + announceUrl
				+ ", pieceQuantity=" + pieceQuantity + ", pieceSizeInBytes="
				+ pieceSizeInBytes + ", creationDate=" + creationDate
				+ ", description=" + description + ", downloadedDate="
				+ downloadedDate + ", torrnet=" + torrnet + ", resourceFiles="
				+ resourceFiles.size() + ", metadataAnnounceUrls="
				+ metadataAnnounceUrls.size() + "]";
	}
}
